//
//  WBRetweetedView.swift
//  CFZWeiBo
//
//  Created by Cedric Zheng on 29/11/2016.
//  Copyright © 2016 Cedric Zheng. All rights reserved.
//

import UIKit

class WBRetweetedView: UIView {
    
    var statusViewModel: WBStatusViewModel? {
        didSet{
            guard let retweetedStatusViewModel = statusViewModel?.retweetedStatusViewModel else {
                textLabel.text = nil
                textLabel.snp.updateConstraints { (make) in
                    make.top.equalToSuperview()
                }
              return
            }
            
            textLabel.snp.updateConstraints { (make) in
                make.top.equalToSuperview().offset(padding)
//                make.bottom.equalToSuperview().offset(-padding)
            }
            
            let retweeterName = retweetedStatusViewModel.screenName ?? ""
            if let retweetedText = retweetedStatusViewModel.text {
                textLabel.text = "@\(retweeterName)：\(retweetedText)"
            }
            
        }
    }
    
    /// 原创微博文字的lable
    lazy var textLabel: UILabel = UILabel(title: "", fontSize: 15)
    
    lazy var pictureView: WBPictureView = WBPictureView()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}

extension WBRetweetedView {
    
    func setupUI() {
        backgroundColor = UIColor.softColor(withHue: .blueHue)
        
        addSubview(textLabel)
        addSubview(pictureView)
        
        textLabel.snp.makeConstraints { (make) in
            make.left.top.equalToSuperview().offset(padding)
            make.right.equalToSuperview().offset(-padding)
        }
        
        //配图视图
        pictureView.snp.makeConstraints { (make) in
            make.top.equalTo(textLabel.snp.bottom).offset(padding)
            make.left.equalTo(textLabel)
            make.size.equalTo(CGSize(width: screenWidth-2*padding, height: screenWidth-2*padding))
            make.bottom.equalToSuperview().offset(-padding)
        }
    }
    
}
